package com.project.service.impl;

import com.project.bean.StuBean;
import com.project.bean.UserBean;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements IUserService {

    @Autowired
    private IUserMapper mapper;

    @Override
    public UserBean login(String username, String pwd) {
        return mapper.login(username,pwd);
    }

    @Override
    public void updatePwd(Integer userId, String newPwd) {
        mapper.updatePwd(userId,newPwd);
    }

    @Override
    public List<UserBean> findAll() {
        return mapper.findAll();
    }

    @Override
    public boolean addUser(UserBean newUser) {
        //用户名重复，返回false
        if (mapper.findUserByUserName(newUser) != 0) {
            return false;
        }
        //用户名不重复，完成添加，返回true
        mapper.addUser(newUser);
        return true;
    }

    @Override
    public void delUser(Integer userId) {
        mapper.delUser(userId);
    }

    @Override
    public UserBean findById(Integer userId) {
        return mapper.findById(userId);
    }

    @Override
    public void updateUserLevel(Integer userId, String newLevel) {
        mapper.updateUserLevel(userId,newLevel);
    }
}
